﻿using System;
using System.Diagnostics;

namespace Antix.Mail.Smtp.Impostor
{
    /// <summary>
    ///   <para>Logging class</para>
    ///   <para>Simple wrapper allowing for change of logging in one place, should I decide to use log4net</para>
    /// </summary>
    public sealed class Log
    {
        static Log()
        {
            ToTrace();
        }

        public static void ToTrace()
        {
            LogInformationAction = m => Trace.TraceInformation(m);
            LogWarningAction = m => Trace.TraceWarning(m);
            LogErrorAction = m => Trace.TraceError(m);
        }

        public static void ToConsole()
        {
            LogInformationAction = Console.WriteLine;
            LogWarningAction = Console.WriteLine;
            LogErrorAction = Console.WriteLine;
        }

        #region actions

        public static Action<string> LogInformationAction { private get; set; }
        public static Action<string> LogWarningAction { private get; set; }
        public static Action<string> LogErrorAction { private get; set; }

        #endregion

        #region methods

        public static void Information(string format)
        {
            LogInformationAction(format);
        }

        public static void Warning(string format)
        {
            LogWarningAction(format);
        }

        public static void Error(string format)
        {
            LogErrorAction(format);
        }

        public static void Error(Exception ex)
        {
            if (ex == null) return;

            LogErrorAction(ex.ToString());
        }

        #endregion
    }
}